﻿<UserControl x:Class="VNet.VisiSuite.Controls.PlantMetrics"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:converter="clr-namespace:VNet.VisiSuite.Common.Converters;assembly=VNet.VisiSuite.Common"
             mc:Ignorable="d" 
             x:Name="_this"
             d:DesignHeight="300" d:DesignWidth="300">

    <UserControl.Resources>
        <converter:ColorStringToColorConverter x:Key="ColorStringToColorConverter"/>
    </UserControl.Resources>
    <Grid DataContext="{Binding ElementName=_this}">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"></ColumnDefinition>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="30" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <TextBlock Text="PLANT METRICS" Foreground="{StaticResource YellowColor}" FontSize="14pt" FontWeight="Bold" Grid.Row="0" HorizontalAlignment="Center" VerticalAlignment="Center"/>
        <Grid Grid.Row="1" Margin="0" HorizontalAlignment="Center">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <Label Style="{StaticResource RightLabelWhiteColorStyle}"
                   Grid.Row="0" Grid.Column="0">Machines Scheduled:</Label>
            <TextBox Grid.Row="0" Style="{StaticResource PlanMetricsTextBoxStyle}" 
                     Foreground="{Binding Path=PlantMetricsData.MachinesScheduledForegroundColor, Converter={StaticResource ColorStringToColorConverter}}"
                     Background="{Binding Path=PlantMetricsData.MachinesScheduledBackgroundColor, Converter={StaticResource ColorStringToColorConverter}}"
                     Grid.Column="1" IsReadOnly="True">
                <MultiBinding StringFormat="{}{0} of {1}">
                    <Binding Path="PlantMetricsData.MachinesScheduled" />
                    <Binding Path="PlantMetricsData.TotalMachines" />
                </MultiBinding>
            </TextBox>
            <Label Style="{StaticResource RightLabelWhiteColorStyle}"
                       Grid.Row="1" Grid.Column="0">Utilization:</Label>
            <TextBox Grid.Row="1" Style="{StaticResource PlanMetricsTextBoxStyle}"
                     Foreground="{Binding Path=PlantMetricsData.UtilizationForegroundColor, Converter={StaticResource ColorStringToColorConverter}}"
                     Background="{Binding Path=PlantMetricsData.UtilizationBackgroundColor, Converter={StaticResource ColorStringToColorConverter}}"
                     Grid.Column="1" IsReadOnly="True" Text="{Binding Path=PlantMetricsData.Utilization, StringFormat={}{0}%}" />
            <Label Style="{StaticResource RightLabelWhiteColorStyle}"
                       Grid.Row="2" Grid.Column="0">Productivity:</Label>
            <TextBox Grid.Row="2" Style="{StaticResource PlanMetricsTextBoxStyle}"
                     Foreground="{Binding Path=PlantMetricsData.ProductivityForegroundColor, Converter={StaticResource ColorStringToColorConverter}}"
                     Background="{Binding Path=PlantMetricsData.ProductivityBackgroundColor, Converter={StaticResource ColorStringToColorConverter}}"
                     Grid.Column="1" IsReadOnly="True" Text="{Binding Path=PlantMetricsData.Productivity, StringFormat={}{0}%}"/>
            <Label Style="{StaticResource RightLabelWhiteColorStyle}"
                       Grid.Row="3" Grid.Column="0"># of Setups:</Label>
            <TextBox Grid.Row="3" Style="{StaticResource PlanMetricsTextBoxStyle}"
                     Foreground="{Binding Path=PlantMetricsData.SetupsForegroundColor, Converter={StaticResource ColorStringToColorConverter}}"
                     Background="{Binding Path=PlantMetricsData.SetupsBackgroundColor, Converter={StaticResource ColorStringToColorConverter}}"
                     Grid.Column="1" IsReadOnly="True" Text="{Binding Path=PlantMetricsData.Setups}"/>
            <Label Style="{StaticResource RightLabelWhiteColorStyle}"
                       Grid.Row="4" Grid.Column="0">Setup Efficiency:</Label>
            <TextBox Grid.Row="4" Style="{StaticResource PlanMetricsTextBoxStyle}"
                     Foreground="{Binding Path=PlantMetricsData.SetupEfficiencyForegroundColor, Converter={StaticResource ColorStringToColorConverter}}"
                     Background="{Binding Path=PlantMetricsData.SetupEfficiencyBackgroundColor, Converter={StaticResource ColorStringToColorConverter}}"
                     Grid.Column="1" IsReadOnly="True" Text="{Binding Path=PlantMetricsData.SetupEfficiency, StringFormat={}{0}%}"/>
        </Grid>

        <Grid  Grid.Row="2" HorizontalAlignment="Center" VerticalAlignment="Center">
            <ItemsControl x:Name="_legend" ItemsSource="{Binding Legend}">
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <UniformGrid Columns="2" />
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal" Margin="0,4,0,6">
                            <TextBlock Background="{Binding Path=Color}" Width="25" Margin ="12,0,0,0" FontSize="14pt"/>
                            <TextBlock Text="{Binding Path=Description}" Style="{StaticResource LegendTextBlockWhiteColorStyle}" Margin ="8,0,0,0"/>
                        </StackPanel>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
        </Grid>
        
    </Grid>
</UserControl>
